/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slicktemplate;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.*;

public class LevelSplashScreen extends BasicGameState {

    private int id;
    private float changescreen = 1000;
    Image splashScreen;
    Image logoScreen;
    private int drawthis = 0;
    Sound introSound;

    public LevelSplashScreen(int id) {
        this.id = id;
    }

    @Override
    public int getID() {
        return id;
    }

    @Override
    public void init(GameContainer container, StateBasedGame game) throws SlickException {
        try {
            splashScreen = new SerializableImage("sprites/splashscreen.png"); //try to load the sprite
            logoScreen = new SerializableImage("sprites/logoscreen.bmp"); //try to load the sprite
            // introSound = new Sound("");
            //  introSound.play();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
        switch (drawthis) {
            case 0:
                splashScreen.draw(0, 0);
                break;
            case 1:
                logoScreen.draw(0, 0);
                break;
            default:
                game.enterState(1);
        }
    }

    @Override
    public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
        Input input = container.getInput();
        if (input.isKeyPressed(Input.KEY_SPACE)) {
            if (drawthis != 1) {
                changescreen -= 1000;
            }
        }

        changescreen -= delta;
        if (changescreen <= 0) {
            drawthis++;
            changescreen = 1000;
        }
        if (drawthis >= 2) {
            game.enterState(1);
        }



    }
}
